import 'package:play_android/com/zhihaoliang/http/HttpException.dart';
import 'package:play_android/com/zhihaoliang/base/BaseRepository.dart';
import 'package:play_android/com/zhihaoliang/const/AppApi.dart';
import 'package:play_android/com/zhihaoliang/http/ResultData.dart';
import 'package:play_android/com/zhihaoliang/http/HttpRequest.dart';

///  ***************************************************************************
///  "登录"请求处理
///  ***************************************************************************

class LoginPresenter extends BaseRepository {
  LoginCallBack _callBack;

  LoginPresenter(this._callBack);

  load(Map param) {
    fetch(AppApi.LOGIN, param)
        .then((_) => _callBack.onLoginComplete())
        .catchError((onError) => _callBack.onLoginError(onError));
  }

  @override
  fetchModel(Map<String, dynamic> map) {
    print("fetchModel");
    return null;
  }

  @override
  Future<ResultData> fetchResultData(
      [String url, Map<String, dynamic> map]) async {
    print("fetchResultData");
    var result = await HttpRequest().post(url, map);
    print("fetchResultData1");
    return result;
  }
}

abstract class LoginCallBack {
  void onLoginComplete();

  void onLoginError(HttpException httpException);
}
